/*
 * Copyright (c) YouYuan 2018. https://gitee.com/you-yuan
 */

package com.yuan.crawler.proxy;

import com.yuan.util.date.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * IP代理API节点
 * @author YouYuan
 * @version 1.0
 * @CreateDate 2018/7/12 17:25
 * @UpdateDate 2018/7/12 17:25
 */
public class ProxyApi {
    /**
     * 代理是否可用
     */
    private boolean isUsable = true;
    /**
     * API地址
     */
    private String apiUrl;
    /**
     * 重新启用时间
     */
    private Date reactivateTime;
    /**
     * 每次禁用时间（分钟）
     */
    private int disableTime;

    public boolean isUsable() {
        return isUsable;
    }

    public void setUsable(boolean usable) {
        isUsable = usable;
    }

    public String getApiUrl() {
        return apiUrl;
    }

    public void setApiUrl(String apiUrl) {
        this.apiUrl = apiUrl;
    }

    public Date getReactivateTime() {
        return reactivateTime;
    }

    public void setReactivateTime(Date reactivateTime) {
        this.reactivateTime = reactivateTime;
    }

    public int getDisableTime() {
        return disableTime;
    }

    public void setDisableTime(int disableTime) {
        this.disableTime = disableTime;
    }

    /**
     * 禁用api
     */
    public void disable(){
        this.isUsable = false;
        this.reactivateTime = DateUtil.addDate(new Date(), Calendar.MINUTE, this.getDisableTime());
    }

    /**
     * 启用api
     */
    public void enable(){
        this.isUsable = true;
        this.reactivateTime = new Date();
    }

    @Override
    public String toString() {
        return "ProxyApi{" +
                "isUsable=" + isUsable +
                ", apiUrl='" + apiUrl + '\'' +
                ", reactivateTime=" + reactivateTime +
                ", disableTime=" + disableTime +
                '}';
    }
}
